<template>
<!--<h1>章节添加编辑</h1>-->
  <el-button type="primary" @click="back">返回章节</el-button>
  <el-button type="primary" @click="oncl">发布</el-button>
  <div>
    <!-- 文章内容 -->
    <h2>编辑{{chaName}}章节</h2>
    <mavon-editor ref="md" v-model="content" style="height:calc(100vh - 260px)"/>
    <h2>编辑题目</h2>
    <mavon-editor ref="md" v-model="htmlcontent" style="height:calc(1vh - 160px)"/>
  </div>




</template>

<script>
import {ElNotification} from "element-plus";

export default {
  props:{
    value:Number,
    chaId:Number,
  },

  name: "ChapterAdd",
  data() {
    return {
      chaId:this.chaId,
      active: 0,
      content:"",
      htmlcontent:"",
      chaCount:{},
      chaName: "",

    }
  },

  mounted() {
    let _this=this
    let chaId=this.chaId;
    // 这样两个组件间就可以进行传值通信了

    let url = "/studyadmin/chapter/chapterContentAll";
    _this.$axios.get(url, {params: {chaId:chaId}}).then(function (serverData) {
      console.log("章节内容数据：", serverData.data)
      _this.chaCount=serverData.data.data
      _this.chaName=serverData.data.data.chaName
      if(serverData.data.data.content==null){
        _this.content="";
      }else {
        _this.content=serverData.data.data.content
      }
      if (serverData.data.data.htmlcontent==null){
        _this.htmlcontent="";
      }else {
        _this.htmlcontent=serverData.data.data.htmlcontent
      }



    })

  },
  methods:{
    back(){
      this.$parent.active=0
    },
    oncl(){
      let _this=this
      let chapterContent={chaId:null,content:"",htmlcontent:""}
      chapterContent.chaId=this.chaId //这里有点小bug
      chapterContent.content=_this.content;
      chapterContent.htmlcontent=_this.htmlcontent;
      let url = "/studyadmin/chapter/chapterContentUpdate";
      _this.$axios.post(url, chapterContent).then(function (serverData) {
        if (serverData.data.code===0){
          ElNotification({
            title: "章节修改成功",
            message: serverData.data.msg,
            type: 'success',
          })
          this.$parent.active=0
        }else {
          ElNotification({
            title: "章节修改失败",
            message: serverData.data.msg,
            type: 'warning',

          })
        }

      })
    }
  },


}
</script>

<style scoped>

</style>





